﻿using System.IO;
using System.Xml;

namespace CDude.Vita
{
    internal class Config
    {
        private const string CONFIG_FILE = "vcconfig.xml";
        public string Language = "default";

        public Config()
        {
            if (File.Exists(CONFIG_FILE))
            {
                XmlTextReader xmlreader = new XmlTextReader(CONFIG_FILE);
                string nodename = null;
                try
                {
                    while (xmlreader.Read())
                    {
                        switch (xmlreader.NodeType)
                        {
                            case XmlNodeType.Element:
                                nodename = xmlreader.Name;
                                break;

                            case XmlNodeType.Text:
                                switch (nodename)
                                {
                                    case "Language":
                                        this.Language = xmlreader.Value;
                                        break;
                                }
                                break;
                        }
                    }
                }
                catch
                {
                }
            }
            else
                Save();
        }

        public void Save()
        {
            using (XmlTextWriter writer = new XmlTextWriter(new FileStream(CONFIG_FILE, FileMode.Create), System.Text.Encoding.Unicode))
            {
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("VCConfig");
                writer.WriteElementString("Language", Language);
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
    }
}